package lights;
/*
* Modified Version
* Author : rendyjr
* Date	  : Jun 10, 2011
* 6.005 Elements of Software Construction
* Rendy Bambang Junior
* rendy.jr@gmail.com
* 
*/
import java.util.ArrayList;
import java.util.List;

public class RunningHolidayLights implements HolidayLights {

	// list contains lights 
	private List<Light> lights;
	
	/**
	 * Creates new running holiday lights.
	 * @param length - length of this set of lights.
	 */
	public RunningHolidayLights(int length) {
		// TODO
		lights = new ArrayList<Light>();
		for(int i = 0; i < length; i++)
			lights.add(new Light());
		lights.get(length-1).setOn(true);
	}
	
	//return list of Light which running
	public List<Light> next() {
		int onIndex = 0;
		// TODO
		for(int i = 0; i < lights.size(); i++){
			if(lights.get(i).isOn()){
				onIndex = i;
				break;
			}
		}
		if(onIndex==lights.size()-1)
			lights.get(0).setOn(true);
		else
			lights.get(onIndex+1).setOn(true);
		
		lights.get(onIndex).setOn(false);
		
		return lights;
	}
	
	/**
	 * Returns the length of this
	 * @return length of this
	 */
	public int getLength() {
		// TODO
		return lights.size();
	}
						
}